import { createApp } from 'vue'
import App from './App.vue'
import install from './install'
import './permission'
import './styles/index.scss'
import 'virtual:svg-icons-register'
import useAppStore from './stores/modules/app'

const app = createApp(App)
app.use(install)
app.mount('#app')

// 自定义全局指令，可以在main.js 的app上注册就可以全局使用
app.directive("city", {
    mounted(el, bindings) {
        const useApp = useAppStore()
        watch(() => useApp.optionCity, () => {
            updateCity(el, bindings)
        }, { immediate: true })
    },
    updated(el, bindings) {
        updateCity(el, bindings)
    }
})

// 抽取公共更新逻辑
function updateCity(el: { innerText: string }, bindings: { value: string | number }) {
    const useApp = useAppStore()
    
    useApp.optionCity.forEach((item: { area_id: string | number; area_short_name: string }) => {
        if (bindings.value == item.area_id) {
            // console.log(bindings.value)
            // console.log(item)
            el.innerText = item.area_short_name
        }
        // else {
        //     el.innerText = '平台'
        // }
    })
}
  
